#ifndef DBTREEWIDGET_H
#define DBTREEWIDGET_H

#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QMenu>
#include <QAction>
#include <QPainter>
#include <QMouseEvent>
#include <QDebug>
#include <QInputDialog>
#include <QFileDialog>
#include <QStringList>

#include "Dialog/catalog/connectmysqldialog.h"
#include "Dialog/catalog/newsqlflayerdialog.h"
#include "Dialog/catalog/addgdbdialog.h"
#include "Geo/geometry/geogeometry.h"
#include "util/appevent.h"
#include "src/SQL/sqloperator.h"
#include "util/env.h"

class DBTreeWidget : public QTreeWidget
{
    Q_OBJECT
public:
    explicit DBTreeWidget(QWidget* parent=nullptr);
    ~DBTreeWidget();

public:
    void iniDBTreeWidget();

signals:
    void sigUpdateOpengl();
    void sigAddNewLayerToLayersTree(GeoLayer* layer);
    void sigSendLayerToGPU(GeoLayer* layer, bool bUpdate = true);
public slots:
    void on_UpdateDBTreeWidget(const QString &root,QTreeWidgetItem* context);
    void on_AddNewSQLFLayer(const QString &layerName,GeometryType geomType);

    void on_actAddDatabase_triggered();
    void on_actNewDatabase_triggered();
    void on_actNewFeatureLayer_triggered();
    void on_actImportShpfile_triggered();
    //void on_actImportCSV_triggered();
    void on_actDeleteFeatureLayer_triggered();
    void on_actImportProject_triggered();
    void on_actDeleteDatabase_triggered();
    void on_actRemoveDatabase_triggered();

    void on_AddGDBData(QString GDBName);

public:
    void createActions();
    void createMenus();
protected:
    void mousePressEvent(QMouseEvent *event) override;
    void contextMenuEvent(QContextMenuEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;

private:
    // RootItem:mysql root
    QTreeWidgetItem *mysqlRootItem;
    //menus
    QMenu *popMenuOnMySQLRootNode;
    QMenu *popMenuOnDBNode;
    QMenu *popMenuOnFLayerNode;
    QMenu *popMenuOnTableNode;
    //actions
    QAction *actAddDatabase;
    QAction *actNewDatabase;
    QAction *actNewFeatureLayer;
    QAction *actImportShpfile;
    QAction *actImportCSV;
    QAction *actDeleteFeatureLayer;
    QAction *actImportProject;
    QAction *actDeleteDatabase;
    QAction *actRemoveDatabase;
};

#endif // DBTREEWIDGET_H
